<?php
class Frontend_QueryController extends Custom_Controller_Action
{
    public function indexAction()
    {
        if (!$this->view->authInfo()->isLogined()) {
            $this->_redirect("/user/login/from/query");
        }
        $form = Wenda::getForm('querySubmit');
        $request = $this->getRequest();
        if ($request->isPost()) {
            $formData = $request->getPost();
            if (Wenda::getModel('Query')->save($formData)) {
                $this->_redirect("index");
            }
            $form->populate($formData);
        }
        $this->view->form = $form;
    }
    
    public function showAction()
    {
        //get query
        $queryId = $this->getRequest()->getParam('ident');
        $query = Wenda::getModel('Query')->findById($queryId);
        if (null === $query) {
            throw new Custom_Exception('No this question data.');
        }
        //set title and keyword
        $this->view->headTitle($query->title, 'PREPEND');
        $this->view->headMeta()->appendName('keywords', $query->title);

        $this->view->bread = Wenda::getModel('Category')->getParents($query->category_id);
    }
}
?>
